package com.office.service;

import com.office.bean.TMajor;
import com.office.utils.DepartBeanUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Majortest {
    @Autowired
    MajorService majorService;

    @Test
    public void test(){
        int pageIndex=0;
        int pagesize=5;
//        int totalcount = majorService.findEmpusercount();//返回总记录数据
//        System.out.println("总记录数为："+totalcount);
//        System.out.println("总页数"+((totalcount%pagesize)==0?(totalcount/pagesize):(totalcount/pagesize+1)));

        Map<String,Object> map = new HashMap<>();
        map.put("pageIndex",pageIndex);
        map.put("pagesize",pagesize);

        List<TMajor> majorBypage = majorService.findMajorBypage(map);
        for (TMajor tMajor : majorBypage) {
            System.out.println(tMajor);
        }
//        System.out.println(majorBypage);
    }

    @Test
    public void addmajor(){

        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = new Date();
        String nowdate = date.format(date1);

        for (int i=0;i<10;i++) {
            TMajor tMajor = new TMajor(0, "pathon课程" + i, "80", nowdate, 3, 0, null);
            majorService.addMajor(tMajor);
        }
    }
    @Test
    public void findid(){
        TMajor findmajorbyid = majorService.findmajorbyid(1);
        System.out.println(findmajorbyid);
    }
    @Test
    public void update(){

        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = new Date();
        String nowdate = date.format(date1);

        int i = majorService.updateMajor(new TMajor(12, "爱情宣传片", "80", nowdate, 5, 0, null));
        System.out.println(i);
    }
}
